package jmine.tec.web.wicket.component.menu;

/**
 * Criador de menus. Deve ser cadastrado no Spring qual o menuId no Html markup e qual a classe que implementa o componente de menu.
 * 
 * @author piercio
 */
public class MenuCreator {

    private String menuId;

    private Class<MenuPrincipal> menuClass;

    private MenuPrincipal menu;

    /**
     * Devolve um menu especifico da classe passada.
     * 
     * @return um {@link AbstractMainMenu}
     */
    public MenuPanel getMenuPanel() {
        if (this.menu == null) {
            try {
                this.menu = this.menuClass.newInstance();
            } catch (InstantiationException e) {
                throw new IllegalStateException(e);
            } catch (IllegalAccessException e) {
                throw new IllegalStateException(e);
            }
        }
        return this.menu.getMenuPanel(this.menuId);
    }

    /**
     * @param menuId the menuId to set
     */
    public void setMenuId(String menuId) {
        this.menuId = menuId;
    }

    /**
     * @param menuClass the menuClass to set
     */
    public void setMenuClass(Class<MenuPrincipal> menuClass) {
        this.menuClass = menuClass;
    }

    /**
     * Define o menu principal
     * 
     * @param menu menu
     */
    public void setMenu(MenuPrincipal menu) {
        this.menu = menu;
    }

}
